#ifndef _DANIEL_KERR_GLSTORY_H
#define _DANIEL_KERR_GLSTORY_H

#include "driver.h"
#include "glScrollingText.h"

#define SCROLL_TIME 20

GAMESTATE storyScreen()
{
	glClearColor(0.0,0.0,0.0,0.0);

	glDisable(GL_DEPTH_TEST);	
	glDisable(GL_LIGHTING);
	glDisable(GL_BLEND);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluOrtho2D(0,X_DIM,Y_DIM,0);

	float r = 0.2,g = 0.2,b = 0.2;
	int mult = 5;

	glScrollingText scroller("levels\\curStory.txt",2.0);
	
	Star_C belt;
	belt.set2Dstars(2000);

	Timer fps;
	SDL_Event event;
	for(int i=0;i<(SCROLL_TIME*35);++i)
	{
		fps.start();

		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

		for(int i = 0; i < belt.NOS(); ++i)
		{
			if(i % 2 == 0)		{glColor4f(r, g, b, 0.9);}
			else				{glColor4f(1-r, 1-g, 1-b, 0.9);}

			glTranslatef(belt.sx(i),belt.sy(i),belt.sz(i));
			glutSolidSphere(belt.ss(i),10,10);
			glTranslatef(-belt.sx(i),-belt.sy(i),-belt.sz(i));
		}

		r += (0.001 * mult);
		g += (0.001 * mult);
		b += (0.001 * mult);

		if((r > 1)||(g > 1)||(b > 1)) mult = mult * -1;
		if((r < 0.2)||(g < 0.2)||(b < 0.2)) mult = mult * -1;

		glColor4f(1,1,1,1.0);
		scroller.draw();

		SDL_GL_SwapBuffers();
		
		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_KEYDOWN)
			{
				switch(event.key.keysym.sym)
				{
					case SDLK_ESCAPE:
					case SDLK_q:		return TITLE; break;
					case SDLK_UP:		scroller.incSpeed(); break;
					case SDLK_DOWN:		scroller.decSpeed(); break;
					default:			return GAME; break;
				};
			}
			else if(event.type == SDL_MOUSEBUTTONDOWN)
			{return GAME;}
		}

		// Cap Frame Rate
		while(fps.get_ticks()<1000/35){}
	}
	return GAME;
}

#endif